//内容
const {contentModel} =require("../mongodb");
const {success,fail} =require("../toast");

module.exports=function(router){
    //查询
    router.get("/content", async ctx=>{
        try {
            const data= await contentModel.find({}); //异步
            return  success(ctx,data);
        } catch (error) {
            return   fail(ctx,error);
        }   
    })
    //添加
    router.post("/content",async ctx=>{
        try {
                const data= await contentModel.create(ctx.request.body); //异步
                return  success(ctx,data);
            } catch (error) {
                return   fail(ctx,error);
            }
       
       })
       //删除
       router.delete("/content",async ctx=>{
        try {
            const data=await contentModel.deleteOne(ctx.request.body); //异步
            return  success(ctx,data);
        } catch (error) {
            return   fail(ctx,error);
        }
    })
    //修改
    router.put("/content",async ctx=>{
        try {
            const data=await contentModel.updateOne(ctx.query,ctx.request.body); //异步
            return  success(ctx,data);
        } catch (error) {
            return   fail(ctx,error);
        }
    })

}